/**
 * 链表节点
 */
class Node {
  data;
  next;

  constructor(data) {
    this.data = data;
  }
}

const isCycle = (head, b = true) => {
  let p1 = head;
  let p2 = head;
  while (p2 && p2.next) {
    p1 = p1.next;
    p2 = p2.next.next;
    if (p1 === p2) {
      return b
    }
  }
  return false
}

const run = ()=>{
  const node1 = new Node(5);
  const node2 = new Node(3);
  const node3 = new Node(7);
  const node4 = new Node(2);
  const node5 = new Node(6);
  node1.next = node2;
  node2.next = node3;
  node3.next = node4;
  node4.next = node5;
  node5.next = node2;
  console.log(isCycle(node1))
}
run()